<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.example.demo.grbkxt.model.Blog" %>
<!DOCTYPE html>
<html>
<head>
    <title>博客列表</title>
    <style>
        .blog-list { margin: 20px; }
        .search-box { margin: 20px; }
        .blog-item { padding: 10px; border-bottom: 1px solid #eee; }
    </style>
</head>
<body>
    <div class="search-box">
        <form action="${pageContext.request.contextPath}/blog/search" method="get">
            <input type="text" name="keyword" placeholder="搜索博客...">
            <select name="category">
                <option value="">所有分类</option>
                <option value="技术">技术</option>
                <option value="生活">生活</option>
                <option value="其他">其他</option>
            </select>
            <button type="submit">搜索</button>
        </form>
    </div>

    <div class="blog-list">
        <% 
        List<Blog> blogs = (List<Blog>)request.getAttribute("blogs");
        if(blogs != null) {
            for(Blog blog : blogs) {
                if(!blog.isAdminOnly()) {
        %>
            <div class="blog-item">
                <h3><%= blog.getTitle() %></h3>
                <p><%= blog.getContent() %></p>
                <small>分类：<%= blog.getCategory() %> | 发布时间：<%= blog.getCreateTime() %></small>
            </div>
        <% 
                }
            }
        } 
        %>
    </div>
</body>
</html>
